/**
 * 
 */
package com.furschina.vo;

import java.util.ArrayList;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;

import com.furschina.model.User;

/**
 * @author iday
 * 
 */
public class LoginUser implements UserDetails {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2515483178811746310L;
	private User user;
	private List<GrantedAuthority> ga;

	/**
	 * 
	 */
	public LoginUser() {
		super();
	}

	/**
	 * @param user
	 */
	public LoginUser(User user) {
		super();
		this.user = user;
		if (user != null) {
			String[] authorities = user.getAuthorities();
			ga = new ArrayList<GrantedAuthority>();
			for (String authority : authorities) {
				ga.add(new GrantedAuthorityImpl(authority));
			}
		}
	}

	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}

	public List<GrantedAuthority> getAuthorities() {
		return ga;
	}

	public String getPassword() {
		return user.getPassword();
	}

	public String getUsername() {
		return user.getUsername();
	}

	public boolean isAccountNonExpired() {
		return true;
	}

	public boolean isAccountNonLocked() {
		return true;
	}

	public boolean isCredentialsNonExpired() {
		return true;
	}

	public boolean isEnabled() {
		return user.isEnabled();
	}
	
	public String getEmail() {
		return user.getEmail();
	}

}
